package com.gmail.blackdog1987.carcare.network.request.builder;

import android.content.Context;

import com.gmail.blackdog1987.carcare.Constant;
import com.gmail.blackdog1987.carcare.db.dao.UserDao;
import com.gmail.blackdog1987.carcare.entity.TUser;
import com.gmail.blackdog1987.carcare.network.request.RequestBuilder;
import com.gmail.blackdog1987.carcare.util.DeviceUtils;
import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class PromotionJoinRequestBuilder extends RequestBuilder {

	private static final String TAG = PromotionJoinRequestBuilder.class.getSimpleName();
	
	private String promotion_id;
	private String name;
	private String phone;
	private String idcard;
	private String driveage;
	
	@Override
	public RequestParams buildRquest() {
		RequestParams params = new RequestParams();
		params.put("promotion_id", promotion_id);
		TUser u = new UserDao().getUser();
		params.put("user_id", String.valueOf(u.id));
		params.put("name", name);
		params.put("phone", phone);
		params.put("idcard", idcard);
		params.put("driveage", driveage);
		return params;
	}

	public PromotionJoinRequestBuilder setPromotion_id(String promotion_id) {
		this.promotion_id = promotion_id;
		return this;
	}

	public PromotionJoinRequestBuilder setName(String name) {
		this.name = name;
		return this;
	}

	public PromotionJoinRequestBuilder setPhone(String phone) {
		this.phone = phone;
		return this;
	}

	public PromotionJoinRequestBuilder setIdcard(String idcard) {
		this.idcard = idcard;
		return this;
	}

	public PromotionJoinRequestBuilder setDriveage(String driveage) {
		this.driveage = driveage;
		return this;
	}

	@Override
	public void postJsonRequest(Context context, AsyncHttpResponseHandler handler) {

		RequestParams params = buildRquest();
		
		AsyncHttpClient client = new AsyncHttpClient();
		client.setTimeout(Constant.TIMEOUT);
		client.setUserAgent(DeviceUtils.OS.getName());
		
		client.post(Constant.Action.PROMOTION_JOIN, params, handler);
		LogUtil.d(TAG, "post : " + params);
	}
}
